package com.ccqlk.basemainapp.database;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class binlog数据恢复 {
    public static void main(String[] args) throws Exception {
        try(BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\Users\\13525\\Music\\decoded8.sql"));
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("C:\\Users\\13525\\Music\\real.sql"))){
            String line;
            String insertSql = """
                        INSERT INTO `light_point_info` (
                          `id`,
                          `box_info_control_code`,
                          `box_info_control_code_new`,
                          `权属管理单位`,
                          `统一社会信用代码`,
                          `管线点编码`,
                          `管线点编号`,
                          `管线类型`,
                          `管线类别`,
                          `X_坐标`,
                          `Y_坐标`,
                          `坐标系`,
                          `地面高程`,
                          `井深`,
                          `特征`,
                          `附属物`,
                          `井盖规格`,
                          `载体`,
                          `建成日期`,
                          `投用日期`,
                          `备注`
                        ) VALUES (
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s,
                          %s
                        );
                    """;

            List<String> oneSqlParams = new ArrayList<>();
            while ((line = bufferedReader.readLine()) != null) {
                if(line.contains("@")){
                    String[] split = line.split("=");
                    oneSqlParams.add(split[1]);

                    if(line.contains("@21")){
                        String formatted = insertSql.formatted(oneSqlParams.toArray());
                        bufferedWriter.write(formatted);
                        oneSqlParams.clear();
                    }
                }
            }
            bufferedReader.close();
            bufferedWriter.flush();
        }

    }
}
